package ca.psquared.superbrixgame;

import org.newdawn.slick.Graphics;

public class QueuedPieceProvider implements IPieceProvider {

    private final IPieceProvider provider;
    private IPiece currentPiece;

    public QueuedPieceProvider(IPieceProvider provider) {
        this.provider = provider;
        currentPiece = provider.getPiece();
    }

    public void render(Graphics graphics) {

        graphics.drawRect(0, 0, 150, 150);
        // Render piece
        int pieceWidth = currentPiece.getWidth();
        int pieceHeight = currentPiece.getHeight();
        int transX = (150 - (pieceWidth * GameSettings.BLOCK_SIZE)) / 2;
        int transY = (150 - (pieceHeight * GameSettings.BLOCK_SIZE)) / 2;
        graphics.pushTransform();
        graphics.translate(transX, transY);
        currentPiece.render(graphics);
        graphics.popTransform();
    }


    @Override
    public IPiece getPiece() {
        final IPiece pieceToReturn = currentPiece;
        currentPiece = provider.getPiece();
        return pieceToReturn;
    }
}